package com.ruoyi.goods.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.CustomExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author {那蓝桉}
 * @Date: 2023/07/28/ 14:33
 * @description 延迟队列配置类
 */
@Configuration
public class DelayedConfig2 {
//    延迟队列名称
    public static final String DELAYED_QUEUE_NAME="11delayed.queue11";
//    延迟交换机名称
    public static final String DELAYED_EXCHANGE_NAME="11delayed.exchange11";
//    routingkey
    public static final String DELAYED_ROUTING_KEY="11delayed.routingkey11";
    @Bean("delayedQueue2")
    public Queue delayedQueue2(){
        return new Queue(DELAYED_QUEUE_NAME);
    }
//    CustomExchange自定义的交换机类型
    @Bean("delayedExchange2")
    public CustomExchange delayedExchange2(){
        Map<String,Object> arguments=new HashMap<>();
        arguments.put("x-delayed-type","direct");
        return new CustomExchange(DELAYED_EXCHANGE_NAME,"x-delayed-message",true,false,arguments);
    }
//    绑定交换机和队列
    @Bean
    public Binding delayedQueueBindingDelayedExchange2(@Qualifier("delayedQueue2") Queue delayedQueue2,@Qualifier("delayedExchange2") CustomExchange delayedExchange2){
        return BindingBuilder.bind(delayedQueue2).to(delayedExchange2).with(DELAYED_ROUTING_KEY).noargs();
    }
}
